package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.Servlet;
import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {
    private static final String USER_IN_SESSION="USER_IN_SESSION";
    private static final String  EXPRESSION_IN_SESSION="EXPRESSION_IN_SESSION";

    private static  HttpSession getSession(){
        ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();

        return attributes.getRequest().getSession();
    }




    public static void setCurrentUser(Employee employee){
       getSession().setAttribute(USER_IN_SESSION,employee);
    }



    public static Employee getCurrentUser(){
        return  (Employee) getSession().getAttribute(USER_IN_SESSION);
    }



    public static void setExpression(List<String> expressions){
        getSession().setAttribute(EXPRESSION_IN_SESSION,expressions);
    }




    public static List<String> getExpression(){
        return (List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION);

    }

}
